package com.tangyuan.user.feign;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tangyuan.common.result.Result;
import com.tangyuan.dto.UserActionByUserIdDto;
import com.tangyuan.dto.UserActionDto;
import com.tangyuan.feignapis.user.IUserActionFeignClient;

import com.tangyuan.model.UserAction;
import com.tangyuan.user.service.UserActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
public class UserActionClient implements IUserActionFeignClient {

    @Autowired
    private UserActionService userActionService;

    @PostMapping("/feignApi/user/getUserAction")
    @Override
    public Result<String> getUserAction(@RequestBody UserActionDto dto){
        return userActionService.action(dto);
    }

    @GetMapping("/feignApi/user/getAllUserMovieId")
    @Override
    public List<Long> getAllUserMovieId() {
        return userActionService.getAllUserMovieId();
    }

    @PostMapping("/feignApi/user/getUserActionByUserIdDto")
    @Override
    public List<Long> getUserActionByUserIdDto(@RequestBody UserActionByUserIdDto userActionByUserIdDto) {
        return userActionService.getUserActionByUserIdDto(userActionByUserIdDto);
    }
    @GetMapping("/feignApi/user/getUserActionByUserId")
    @Override
    public List<Long> getUserActionByUserId(@RequestParam Long userId) {
        return userActionService.getUserActionByUserId(userId);
    }
    @GetMapping("/feignApi/user/getPageUserActionByUserId")
    @Override
    public Page<UserAction> getPageUserActionByUserId(@RequestParam Long userId, @RequestParam Integer pageNum,@RequestParam Integer pageSize){
        return userActionService.getPageUserActionByUserId(userId,pageNum,pageSize);
    }

    @PostMapping("/feignApi/user/addUserAction")
    public void addUserAction(@RequestParam(value = "userId") Long userId, @RequestParam(value = "movieId") Long movieId){
        userActionService.addUserAction(userId, movieId);
    }

    @GetMapping("/feignApi/user/getAllUserId")
    public List<Long> getAllUserId(){
        return userActionService.getAllUserId();
    }

    @GetMapping("/feignApi/user/getUserActionCollection")
    public List<UserAction> getUserActionCollection(){
        return userActionService.getUserActionCollection();
    }

    @PostMapping("/feignApi/user/deleteUserAction")
    public void deleteUserAction(){
        userActionService.deleteUserAction();
    }

    @GetMapping("/feignApi/user/selectUserActionList")
    public List<UserAction> selectUserActionList(@RequestParam(value = "userId") Long userId,@RequestParam(value = "sort",required = false) String sort){
        return userActionService.selectUserActionList(userId,sort);
    }

    @GetMapping("/feignApi/user/selectUserActionListByDistinct")
    public List<UserAction> selectUserActionListByDistinct(){
        return userActionService.selectUserActionListByDistinct();
    }

    @PostMapping("/feignApi/user/view")
    public void view(@RequestBody UserAction userAction){
        userActionService.view(userAction);
    }

    @GetMapping("/feignApi/user/getYesterdayUserActionData")
    public List<UserAction> getYesterdayUserActionData(@RequestParam(required = false) Date time) {
        return userActionService.getYesterdayUserActionData(time);
    }
}
